package 强化训练;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class day42迷宫问题 {

    static class Point{
        int x ;
        int y ;
        public Point(int x,int y){this.x = x;this.y = y;}
    }
    static int N = 10;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       while (sc.hasNext()){
           char[][] mg = new char[N][N];
           char[][] tem = new char[N][N];
           for (int i = 0; i < N; i++) {
               String s = sc.nextLine();
               char[] chars = s.toCharArray();
               for (int j = 0; j < N; j++) {
                   mg[i][j] = chars[j];
                   tem[i][j] = mg[i][j];
               }
           }
           ArrayList<Point> way = new ArrayList<>();
           ArrayList<List<Point>> res = new ArrayList<>();

           System.out.println(DFS(tem,1,1,way,res));
           int min = Integer.MAX_VALUE;
           for (List l : res){
               min = min > l.size() ? l.size() : min;
           }
           System.out.println(min);
       }
    }

    private static boolean DFS(char[][] tem ,int i,int j,ArrayList<Point> way,ArrayList<List<Point>> res){
        if (i == N-1 && j == N-2){
            way.add(new Point(i,j));
            List<Point> list = new ArrayList<>(way);
            res.add(list);
            return true;
        }
        tem[i][j] = '#';
        way.add(new Point(i,j));
        boolean down = false,right = false,up = false,left = false;
        //向下
        if (i+1 < N && tem[i+1][j] != '#'){
            down = DFS(tem,i+1,j,way,res);
        }
        //向右
        if (j+1 < N && tem[i][j+1] != '#'){
            right = DFS(tem,i,j+1,way,res);
        }
        //向左
        if (j-1 > 0 && tem[i][j-1] != '#'){
            left = DFS(tem,i,j-1,way,res) ;
        }
        //向上
        if (i-1 > 0 && tem[i-1][j] != '#'){
            up = DFS(tem,i-1,j,way,res) ;
        }
        way.remove(way.size()-1);
//        tem[i][j] = '.';
        return up || down || left || right;
    }
}
